<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../css/style.css">
        <script src="../js/echarts.js"></script>
        <script src="../plugins/datapicker/datePicker.js"></script>
        <link rel="stylesheet" href="../plugins/elementui/index.css" />
        <script src="../plugins/jquery/dist/jquery.min.js"></script>
        <script src="../plugins/vue/vue.js"></script>
        <script src="../plugins/vue/axios-0.18.0.js"></script>
        <script src="../plugins/elementui/index.js"></script>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>统计分析<small>会员数量</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>统计分析</el-breadcrumb-item>
                    <el-breadcrumb-item>会员数量</el-breadcrumb-item>
                </el-breadcrumb>


                <template>
                    <div class="block">
                        <span class="demonstration">请选择日期：</span>
                        <el-date-picker
                                v-model="regTime"
                                @change="dateChangeregTime"
                                type="daterange"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd"
                                align="right"
                                unlink-panels
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                :picker-options="pickerOptions">
                        </el-date-picker>
                        <el-button @click="submitDate()" class="dalfBut">查询</el-button>
                    </div>
                </template>




            </div>
            <div class="app-container">
                <div class="box">
                    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
                    <div id="chart1" style="height:600px;"></div>
                </div>
            </div>

            <div class="app-container">
                <div class="box">
                    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
                    <div id="chart2" style="height:600px;"></div>
                </div>
            </div>


            <div class="app-container">
                <div class="box">
                    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
                    <div id="chart3" style="height:600px;"></div>
                </div>
            </div>


        </div>


        <script>
            var Main={
                data() {
                    return {
                        pickerOptions: {
                            shortcuts: [{
                                text: '最近一周',
                                onClick(picker) {
                                    const end = new Date();
                                    const start = new Date();
                                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                    picker.$emit('pick', [start, end]);
                                }
                            }, {
                                text: '最近一个月',
                                onClick(picker) {
                                    const end = new Date();
                                    const start = new Date();
                                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                    picker.$emit('pick', [start, end]);
                                }
                            }, {
                                text: '最近三个月',
                                onClick(picker) {
                                    const end = new Date();
                                    const start = new Date();
                                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                    picker.$emit('pick', [start, end]);
                                }
                            }]
                        },
                        regTime: '',
                        strTime:'',
                    };
                },

                methods: {
                         dateChangeregTime(val) {
                    this.starttime = val[0];
                    this.endtime = val[1];
                   console.log(this.starttime);
                   console.log(this.endtime);
                },
                    submitDate(){
                        // 基于准备好的dom，初始化echarts实例
                        var myChart1 = echarts.init(document.getElementById('chart1'));

                        // 使用刚指定的配置项和数据显示图表。
                        //myChart.setOption(option);
                        /*var map={}
                            map.starttime=this.starttime,
                            map.endtime=this.endtime,
                */

                        var url;
                        if (this.starttime==null||this.endtime==null){
                            this.url="http://oms.backend.health:82/report/getMemberReport.do"
                        } else {
                            this.url="http://oms.backend.health:82/report/getMemberReport.do?starttime="+this.starttime+"&endtime="+this.endtime
                        }
                        axios.get(this.url).then((res)=>{
                            myChart1.setOption(
                                {
                                    title: {
                                        text: '会员数量'
                                    },
                                    tooltip: {},
                                    legend: {
                                        data:['会员数量']
                                    },
                                    xAxis: {
                                        data: res.data.data.months
                                    },
                                    yAxis: {
                                        type:'value'
                                    },
                                    series: [{
                                        name: '会员数量',
                                        type: 'line',
                                        data: res.data.data.memberCount
                                    }]
                                });
                        });

                    }
             }
             };
            var Ctor=Vue.extend(Main)
            new Ctor().$mount('#app')
        </script>


    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart1 = echarts.init(document.getElementById('chart1'));

        // 使用刚指定的配置项和数据显示图表。
        //myChart.setOption(option);
        /*var map={}
            map.starttime=this.starttime,
            map.endtime=this.endtime,
*/

        var url;
        if (this.starttime==null||this.endtime==null){
            this.url="http://oms.backend.health:82/report/getMemberReport.do"
        } else {
            this.url="http://oms.backend.health:82/report/getMemberReport.do?starttime="+this.starttime+"&endtime="+this.endtime
        }
        axios.get(this.url).then((res)=>{
            myChart1.setOption(
                                {
                                    title: {
                                        text: '会员数量'
                                    },
                                    tooltip: {},
                                    legend: {
                                        data:['会员数量']
                                    },
                                    xAxis: {
                                        data: res.data.data.months
                                    },
                                    yAxis: {
                                        type:'value'
                                    },
                                    series: [{
                                        name: '会员数量',
                                        type: 'line',
                                        data: res.data.data.memberCount
                                    }]
                                });
        });

    </script>
    <script type="text/javascript">
        var myChart2 = echarts.init(document.getElementById('chart2'));

        // 使用刚指定的配置项和数据显示图表。
        //myChart.setOption(option);

        axios.get("http://oms.backend.health:82/report/getMemberReportBySex.do").then((res)=>{
            myChart2.setOption(
                {
                    title : {
                        text: '会员数量性别占比',
                        subtext: '',
                        x:'center'
                    },
                    tooltip : {//提示框组件
                        trigger: 'item',//触发类型，在饼形图中为item
                        formatter: "{a} <br/>{b} : {c} ({d}%)"//提示内容格式
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: res.data.data.sexs,
                    },
                    series : [
                        {
                            name: '会员性别数量占比',
                            type: 'pie',
                            radius : '55%',
                            center: ['50%', '60%'],
                            data:res.data.data.sexCount,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                });
        });
    </script>
    <script type="text/javascript">
        var myChart3 = echarts.init(document.getElementById('chart3'));

        // 使用刚指定的配置项和数据显示图表。
        //myChart.setOption(option);

        axios.get("http://oms.backend.health:82/report/getMemberReportByAge.do").then((res)=>{
            myChart3.setOption(
                {
                    title : {
                        text: '会员数量年龄占比',
                        subtext: '',
                        x:'center'
                    },
                    tooltip : {//提示框组件
                        trigger: 'item',//触发类型，在饼形图中为item
                        formatter: "{a} <br/>{b} : {c} ({d}%)"//提示内容格式
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: res.data.data.agePhaseNames
                    },
                    series : [
                        {
                            name: '会员年龄数量占比',
                            type: 'pie',
                            radius : '55%',
                            center: ['50%', '60%'],
                            data:res.data.data.ageCount,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                });
        });
    </script>

</html>
